package cn.test.my.excel.poi.convert;


import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * excel java数据处理
 *
 * @author summit
 * @since 2021/6/6 20:14
 */
public class DefaultConverterLoader {

    private static Map<String, Converter<?>> CONVERTER_MAP;

    static {
        initConverter();
    }

    private static void initConverter() {
        CONVERTER_MAP = new ConcurrentHashMap<>(16);
        putConverter(new StringConverter());
        putConverter(new LocalDateConverter());
        putConverter(new LocalDateTimeConverter());
        putConverter(new IntegerConverter());
        putConverter(new BigDecimalConverter());
    }

    private static void putConverter(Converter<?> converter) {
        CONVERTER_MAP.put(converter.supportJavaTypeKey().getSimpleName(), converter);
    }


    public static Map<String, Converter<?>> loadDefaultConverter() {
        return CONVERTER_MAP;
    }

	public static Converter<?> getConverter(Class<?> clazz) {
		return CONVERTER_MAP.get(clazz.getSimpleName());
	}
}
